import redis


class Get_Pool():
    """
    Redis连接的类
    """

    def __init__(self, host, port, max_connections):
        """
        初始化变量
        :param host: 指定Redis的环境
        :param port: Redis的端口
        :param max_connections: Redis最大连接数
        """
        self.host = host
        self.port = port
        self.max_connections = max_connections

    def get_pool(self, db):
        """
        创建redis连接池
        :param db: 指定Redis库id
        :return: 返回Redis连接池
        """
        try:
            pool = redis.ConnectionPool(
                host=self.host,
                port=self.port,
                db=db,
                max_connections=self.max_connections
            )
        except Exception as e:
            print(e)
        return pool
